import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from common.base import Base
from common.functions import open_browser


class LoginPage(Base):

    def login_url(self):
        self.get('http://139.129.26.163/admin/privilege.php?act=login')

    # 定位用户名输入框并输入内容
    def input_username(self, username):
        self.find_element((By.NAME, "username")).send_keys(username)

    # 定位密码输入框并输入内容
    def input_password(self, password):
        self.find_element(("name","password")).send_keys(password)

    # 定位登录按钮并点击
    def login_click(self):
        self.click((By.CLASS_NAME,"btn-a"))

    # 退出登录
    def new_quit(self):
        # self.into_frame((By.ID, 'menu-frame'))
        self.click((By.XPATH,'//div[@id="foot-div"]'))
        # ac = ActionChains(self.driver)
        # ac.move_to_element(ele).perform()
        self.click((By.XPATH,'//li[@class="btn-exit"]/a'))

    # 退出浏览器
    def q(self):
        self.quit(3)

    # 前台
    #  定义LoginPage类，继承Base类
        #  定位账号输入框，输入数据
    def input_username1(self, username):
        self.find_element((By.NAME, 'username')).send_keys(username)

        #  定位密码输入框，输入数据
    def input_password1(self, password):
        self.find_element((By.NAME, 'password')).send_keys(password)

        #  定位保存信息框，点击
    def remember(self):
        self.click((By.NAME, 'remember'))

        #  定位登录按钮，点击
    def btn_login(self):
        self.click((By.NAME, 'submit'))

        # 定位到请登录按钮
    def please_login(self):
        self.click((By.LINK_TEXT, '请登录 '))

        # 定位登录文本
    def get_login_text(self):
        self.get_element_text((By.LINK_TEXT, '请登录 '))


    login_url1 = 'http://139.129.26.163/user.php'
    def input_username2(self, username):
        self.send_keys((By.XPATH, '//input[@name="username"]'), username)

    def input_password2(self, password):
        self.send_keys((By.XPATH, '//input[@name="password"]'), password)

    # def remember(self):
    #     self.click(('id', 'remember'))

    def login(self):
        self.click((By.XPATH, '//input[@name="submit"]'))



    # 刘丹丹
    login_url2 = 'http://139.129.26.163/user.php'

    def input_uesrname3(self, username):
        self.send_keys((By.XPATH, "//input[@name='username']"), username)

    def input_password3(self, password):
        self.send_keys((By.XPATH, "//input[@name='password']"), password)

    # def remember(self):
    #     self.click((By.ID, 'remember'))

    def btn_login3(self):
        self.click((By.XPATH, "//input[@name='submit']"))


if __name__ == '__main__':
    browser = open_browser()
    login = LoginPage(browser)
    login.login_url()
    time.sleep(2)
    login.input_username("admin")
    login.input_password("admin123")
    login.login_click()
    time.sleep(3)
    login.new_quit()
    login.q()
    time.sleep(2)